
import { getTypeOf } from './getDataTypeStr.js'
import { DATA_TYPE_STRING } from './dataType.js';

function is(data, type) {
    return getTypeOf(data) === type;
}

export function isString(data) {
    return is(data, DATA_TYPE_STRING.String);
}

/**
 * is number
 * @deprecated 替换为 `${isStrictNumber}`
 * @param {*} data 
 * @returns 
 */
export function isNumber(data) {
    return is(data, DATA_TYPE_STRING.Number);
}
export function isBoolean(data) {
    return is(data, DATA_TYPE_STRING.Boolean);
}
export function isUndefined(data) {
    return is(data, DATA_TYPE_STRING.Undefined);
}
export function isNull(data) {
    return is(data, DATA_TYPE_STRING.Null)
}
export function isSymbol(data) {
    return is(data, DATA_TYPE_STRING.Symbol)
}
export function isArray(data) {
    return is(data, DATA_TYPE_STRING.Array)
}
export function isObject(data) {
    return is(data, DATA_TYPE_STRING.Object)
}
export function isFunction(data) {
    return is(data, DATA_TYPE_STRING.Function)
}

/**
 * 严格数字
 * @param {*} data 
 * @returns 
 */
export function isStrictNumber(data) {
    return is(data, DATA_TYPE_STRING.Number);
}

/**
 * 数字 字符串类数字
 * @param {*} data 
 */
export function isWeakNumber(data) {
    if (typeof data === 'number') return true;
    if (typeof data != 'string') return false;

    // 字符串类型数字
    if (data == +data) return true;

    return false;
}